//
//  RecentWinNumberViewController.m
//  CaiPiao
//
//  Created by apple on 2018/5/20.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "RecentWinNumberViewController.h"
#import "RecentWNumTableViewCell.h"

@interface RecentWinNumberViewController ()
@property (weak, nonatomic) IBOutlet UITableView *winNumberTableView;
@property(nonatomic,retain)NSArray* winNumberArrary;
@end

@implementation RecentWinNumberViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.layer.cornerRadius = 15;
    self.view.layer.masksToBounds = YES;
    [self.winNumberTableView registerNib:[UINib nibWithNibName:@"RecentWinNumberCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"RecentWNumTableViewCell"];

    
    [[SelectionNumManager shared] getDataWithLotteryID:[SelectionNumManager shared].currentLotteryID andActionID:@"202" andCallBack:^(BOOL load, NSDictionary *resObj) {
        if (load) {
            self.winNumberArrary = resObj[@"data"];
            [self.winNumberTableView reloadData];
        }
    }];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.winNumberArrary count];
}
//{
//    ID = 774124;
//    Name = 2018047;
//    WinNumber = "06 07 12 16 22 25+07";
//    WinSum = 0;
//    WinType = "";
//},
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RecentWNumTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"RecentWNumTableViewCell"];
    NSLog(@"cell = %@",cell);
    if(nil == cell) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"RecentWinNumberCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    NSDictionary* dic = self.winNumberArrary[indexPath.row];
    cell.nameLabel.text = [NSString stringWithFormat:@"%@ 期",dic[@"Name"]];
    
    NSArray* winNumberArray = [dic[@"WinNumber"] componentsSeparatedByString:@"+"];
    
    cell.redWinNumberLabel.text = winNumberArray[0];
    if ([winNumberArray count]>1) {
        cell.blueWinNumberLabel.text = winNumberArray[1];
    }
    
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
